<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('图片类型列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <a class="btn btn-success" onclick="imagesTypeAdd()">
            <i class="fa fa-plus"></i> 添加
        </a>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">

    var prefix = "/advert/type";
    $(function() {
        var options = {
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            url: prefix + "/list.json",
            removeUrl: prefix + "/remove.json",
            modalName: "图片类型",
            columns: [
                {
                    field: 'typeId',
                    title: 'id',
                    width: '100px'
                },
                {
                    field: 'typeName',
                    title: '类型名称'
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '120px',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="imagesTypeEdit(\'' + row.typeId + '\',\'' + row.typeName + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.typeId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function imagesTypeAdd() {
        layer.prompt({title: '输入广告类型名称，并确认', formType: 0}, function(pass, index){
            $.post(prefix+"/add.json",{"typeName":pass},function(json){
                if(json.code === 0){
                    layer.close(index);
                    window.location.reload();
                }else{
                    $.modal.msgError(json.msg)
                }
            });
        });
    }

    function imagesTypeEdit(typeId,typeName) {
        layer.prompt({title: '修改广告类型名称，并确认',value:typeName, formType: 0}, function(pass, index){
            $.post(prefix+"/edit.json",{"typeId":typeId,"typeName":pass},function(json){
                if(json.code === 0){
                    layer.close(index);
                    window.location.reload();
                }else{
                    $.modal.msgError(json.msg)
                }
            });
        });
    }
</script>
</body>
</html>